#ifndef TREEMODEL_H
#define TREEMODEL_H

#include <QAbstractItemModel>

class TreeModel : public QAbstractItemModel
{
    Q_OBJECT

public:
    explicit TreeModel(QObject *parent = nullptr);
    ~TreeModel(){delete _rootItem;}
    // Header:
    //QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;

    // Basic functionality:
    QModelIndex index(int row, int column,
                      const QModelIndex &parent = QModelIndex()) const override;
    QModelIndex parent(const QModelIndex &index) const override;

    int rowCount(const QModelIndex &parent = QModelIndex()) const override;
    int columnCount(const QModelIndex &parent = QModelIndex()) const override;

    QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;

    void setColumns(QStringList cols){m_columns = cols;}
    void AddItem(QObject* item, const QModelIndex & parentIndex);

    QObject* rootItem(){return _rootItem;}


protected:
QStringList m_columns;
QObject* _rootItem;
QObject* objByIndex(const QModelIndex &index) const;
QModelIndex IndexById(QString id) const;

private:
friend class TreeApp;
};

#endif // TREEMODEL_H
